//
//  AlbumDetailsViewController.m
//  EDPS
//
//  Created by Neil on 15/11/26.
//  Copyright © 2015年 张维扬. All rights reserved.
//

#import "AlbumDetailsViewController.h"
#import "DestinationAlbumCollectionViewCell.h"
#import "item.h"
#import "UIImageView+WebCache.h"

@interface AlbumDetailsViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) UICollectionView *collectionView;
@property (nonatomic, retain) UILabel *detialsLable;
@property (nonatomic, retain) UILabel *countLable;

@end

@implementation AlbumDetailsViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self creatCollectionView];
}

#pragma mark - 创建collectionView
- (void)creatCollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height - 220);
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) collectionViewLayout:layout];
    self.collectionView.delegate = self;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.dataSource = self;
    [self.collectionView registerClass:[DestinationAlbumCollectionViewCell class] forCellWithReuseIdentifier:@"twoCell"];
    [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
    
    self.collectionView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
    self.collectionView.contentOffset = CGPointMake(self.view.frame.size.width * self.inter, 0);
    self.collectionView.pagingEnabled = YES;
    [self.view addSubview:self.collectionView];
    
    self.detialsLable = [[UILabel alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height - 110, self.view.frame.size.width, 110)];
    self.detialsLable.font = [UIFont systemFontOfSize:10];
    self.detialsLable.numberOfLines = 0;
    self.detialsLable.textColor = [UIColor blackColor];
    [self.view addSubview:self.detialsLable];
    
    self.countLable = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width / 5 * 4, self.view.frame.size.height - 180, 70, 70)];
    self.countLable.textColor = [UIColor whiteColor];
//    self.countLable.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:self.countLable];
    
    UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
    back.frame = CGRectMake(20, 25, 40, 40);
    
    [back setBackgroundImage:[UIImage imageNamed:@"iconfont-fan"] forState:UIControlStateNormal];
    [back addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:back];
    
    
}

#pragma mark - 返回按钮
- (void)backAction
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

#pragma mark - collectionView方法
#pragma mark - 点击方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
}

#pragma mark - cell个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.imgArr.count;
}

#pragma mark - cell内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    DestinationAlbumCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"twoCell" forIndexPath:indexPath];
        [cell.postImgView sd_setImageWithURL:[NSURL URLWithString:[self.imgArr[indexPath.row] photo_1600]]];
    
    self.detialsLable.text = [self.imgArr[indexPath.row] text];
    
    self.countLable.text = [NSString stringWithFormat:@"%ld/%ld", (indexPath.item + 1), self.imgArr.count];
 //   NSLog(@"%@", [NSString stringWithFormat:@"%ld/%ld", (indexPath.item + 1), self.imgArr.count]);
    
    cell.backgroundColor = [UIColor grayColor];
    
    return cell;
    
}


@end
